package com.adulcimer.controllers;

import cn.dev33.satoken.annotation.SaIgnore;
import com.adulcimer.core.tools.R;
import com.adulcimer.models.entity.domain.Posts;
import com.adulcimer.models.dto.DemonIdsStringDto;
import com.adulcimer.models.dto.PostsSaveDto;
import com.adulcimer.core.tools.DemonPagingModel;
import com.adulcimer.services.LocalPostsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Simon
 * @create 2025/2/6
 * @Description
 **/

@RestController
@RequestMapping("/api/posts")
@Tag(name = "文章接口", description = "文章接口")
public class PostsController extends BaseController {

    @Resource
    private LocalPostsService localPostsService;

    @GetMapping("/list")
    @Operation(summary = "文章列表")
    @Parameter(name = "pageNumber", description = "页码", required = true)
    @Parameter(name = "pageSize", description = "每页数量", required = true)
    @Parameter(name = "status", description = "文章是否启用")
    @SaIgnore
    public R<DemonPagingModel<List<Posts>>> list(@RequestParam(defaultValue = "1") Integer pageNumber,
                                                 @RequestParam(defaultValue = "20") Integer pageSize,
                                                 @RequestParam(defaultValue = "1") Integer status,
                                                 @RequestParam(required = false) String q){
        return R.ok(localPostsService.list(pageNumber, pageSize, status, q));
    }

    @PostMapping("/save")
    @Operation(summary = "保存文章")
    public R<String> save(@RequestBody PostsSaveDto postsSaveDto){
        localPostsService.save(postsSaveDto);
        return R.ok();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除文章")
    public R<String> delete(@RequestBody DemonIdsStringDto ids){
        localPostsService.delete(ids);
        return R.ok();
    }



}


